﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for ENU
/// </summary>
public sealed class ENU
{
    public enum Entity
    {
        Customer = 0,
        Client = 1
    }
    public enum CCLoVRecordType
    { 
        Contact=0,
        Identity=1,
        Family=2,
        CV=3,
        CVSensitive=4,
        Other=5,
        Legal=6
    }
    public enum CCLoVRecordName
    {
        PassportNo=0,
        BirthDate=1,
        BirthPlace=2,
        Nationality=3,
        Phone=4,
        Address=5,
        Other=6,
        Salary=7,
        ExpirationDate=8,
        BookingNumber=9
    }
    public enum CCLovLoadOption
    { 
        LoadAll=0,
        LoadOneRecordType=1,
        LoadOneRecordNameUnderARecordType= 2
    }
    public enum ENTOperation
    { 
        Update=0,
        Delete=1,
        Insert=2
    }
    public enum RecStatus
    {
        NoChange=0,
        Added=1,
        Modified=2,
        Deleted=3
    }
    public enum WFCode
    {
        RP=0,
        WP=1,
        AS=2,
        HL=3,
        HS=4,
        SS=5,
        FS=6,
        BV=7
    }
    public enum WFICompletionStatus
    { 
        Started=0,
        Completed=1,
        Cancelled=2
    }

    public List<KeyValuePair<CCLoVRecordType, CCLoVRecordName>> CCLoVRecordTypeNameList()
    {
        var list = new List<KeyValuePair<CCLoVRecordType, CCLoVRecordName>>();
        list.Add(new KeyValuePair<CCLoVRecordType, CCLoVRecordName>(CCLoVRecordType.Contact, CCLoVRecordName.Phone));
        list.Add(new KeyValuePair<CCLoVRecordType, CCLoVRecordName>(CCLoVRecordType.Contact, CCLoVRecordName.Address));

        return list;
    }
    /// <summary>
    /// Converts ENUM Values to DataTable with given KeyName, KeyLabel as column names
    /// i.e ENU.EnumToDataTable(typeof(ENU.ModelDataType), "RecordId", "RecordLabel");
    /// </summary>
    /// <param name="EnumObject">Enum itself </param>
    /// <param name="KeyField">Column name of key field when it returns datatable</param>
    /// <param name="ValueField">Column name of key label when it returns datatable</param>
    /// <returns></returns>
    public static DataTable EnumToDataTable(Type EnumObject, string KeyField, string ValueField)
    {

        DataTable oData = null;
        DataRow oRow = null;
        DataColumn oColumn = null;

        // Sanity check
        if (KeyField.Trim() == string.Empty)
        {
            KeyField = "KEY";
        }

        if (ValueField.Trim() == string.Empty)
        {
            ValueField = "VALUE";
        }

        // Create the DataTable
        oData = new DataTable();

        oColumn = new DataColumn(KeyField, typeof(System.Int32));
        oData.Columns.Add(KeyField);

        oColumn = new DataColumn(ValueField, typeof(System.String));
        oData.Columns.Add(ValueField);

        // Add the enum items to the datatable
        foreach (object iEnumItem in Enum.GetValues(EnumObject))
        {
            oRow = oData.NewRow();
            oRow[KeyField] = (Int32)iEnumItem;
            oRow[ValueField] = iEnumItem.ToString();
            oData.Rows.Add(oRow);
        }

        return oData;

    }
    public static Entity EntityParse(string strval)
    {
        return (Entity)Enum.Parse(typeof(Entity), strval);
    }
    public static Entity EntityParse(int intval)
    {
        return (Entity)intval;
    }
    public static int EntityParse(Entity enumval)
    {
        return (Int32)enumval;
    }
    public static CCLoVRecordType RecordTypeParse(string strval)
    {
        return (CCLoVRecordType)Enum.Parse(typeof(CCLoVRecordType), strval);
    }
    public static CCLoVRecordType RecordTypeParse(int intval)
    {
        return (CCLoVRecordType)intval;
    }
    public static int RecordTypeParse(CCLoVRecordType enumval)
    {
        return (Int32)enumval;
    }
    public static CCLoVRecordName RecordNameParse(string strval)
    {
        return (CCLoVRecordName)Enum.Parse(typeof(CCLoVRecordName), strval);
    }
    public static CCLoVRecordName RecordNameParse(int intval)
    {
        return (CCLoVRecordName)intval;
    }
    public static int RecordNameParse(CCLoVRecordName enumval)
    {
        return (Int32)enumval;
    }
    public static CCLovLoadOption LoadOptionParse(string strval)
    {
        return (CCLovLoadOption)Enum.Parse(typeof(CCLovLoadOption), strval);
    }
    public static int WFCodeParse(WFCode enumval)
    {
        return (Int32)enumval;
    }
    public static WFCode WFCodeParse(int intval)
    {
        return (WFCode)intval;
    }
    public static WFCode WFCodeParse(string strval)
    {
        return (WFCode)Enum.Parse(typeof(WFCode), strval);
    }

}